<template>
  <div class="main_form">
    <div
      v-for="(config, index) in configFormList"
      :key="config.title + index"
    >
      <aiTitle :title="config.title" />
      <div class="final_content">
        <div class="icon_box">
         <div class="doning_prcoress"  v-if="finalStatus === 2">
          <div class="process_card" v-if="processText!=='0%'">{{ processText }}</div>
          <div
            class="create_box" >
          </div>
         </div>
          <img
            v-if="finalStatus === 0"
            src="@/static/img/AI_stop.png"
            alt="已停止生成文稿"
            class="icon-stop">
          <img
            v-if="finalStatus === 1"
            src="@/static/img/AI_finish.png"
            alt="生成完成"
            class="icon-finish">
          <p class="rate-text">{{ resultText }}</p>
        </div>
        <div v-if="finalStatus !== 2">
          <p class="rate-text rate-tips">请为我们打分吧!</p>
          <el-rate
            v-model="writeRate"
            :colors="['#99A9BF', '#F7BA2A', '#FF9900']"
            class="write-rate"
            @change="handleChangeRate">
          </el-rate>
          <p
            v-if="writeRate"
            class="rate-text rate-evaluate rate-tips">谢谢评价，我们会继续努力的！</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import aiTitle from './aiTitle.vue'
import { updateScoreInfoById } from '@/api/writing'

export default {
  components: { aiTitle },
  props: {
    finalStatus: {//0.停止生成 1.生成完成 2.正在生成
      type: Number,
      default: 2
    },
    processText: {
      type: String,
      default: '0%'
    },
    configFormList: {
      type: Array,
      default: () => []
    },
    recordData: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      writeRate: null,
      rateId: '',
      statusList: [
        {
          value: 2,
          name: '正在生成文稿，请等待···'
        },
        {
          value: 0,
          name: '已停止生成文稿'
        },
        {
          value: 1,
          name: '生成完成'
        }
      ]
    }
  },
  watch: {
    finalStatus () {
      this.writeRate = null
      this.rateId = ''
    },
  },
  computed: {
    resultText () {
      let status = this.statusList.find(el => el.value === this.finalStatus) || {}
      return status.name || '正在生成文稿，请等待···'
    },
    userInfo () {
      return JSON.parse(wps.PluginStorage.getItem('LoginInfo'))
    }
  },
  methods: {
    handleChangeRate (score) {
      updateScoreInfoById({
        id: this.rateId || '',
        userId: this.userInfo.usercode,
        userName: this.userInfo.username,
        score: score,
        generateStatus: this.finalStatus,
        uniquenessObj: this.recordData
      }).then((res) => {
        this.rateId = res.data.id || ''
      })
    }
  }
}
</script>

<style scoped>
.main_form {
  height: 100%;
  padding: 0 10px 10px;
  box-sizing: border-box;
}
.final_content {
  height: 665px;
  border-radius: 4px;
  box-sizing: border-box;
  background-color: #FFF;
  box-shadow: 0 0 4px 0 rgba(0, 0, 0, .2);
}
.rate-text {
  font-size: 14px;
  text-align: center;
}
.rate-evaluate {
  padding: 10px 0;
}
.rate-tips {
  color: #909199;
}
.write-rate {
  text-align: center;
  height: max-content;
  padding: 10px 0;
}
.write-rate.el-rate >>> .el-rate__item i.el-rate__icon {
  font-size: 36px;
}
.icon_box {
  text-align: center;
  padding: 40px 0 20px 0;
}
.process_box {
  width: 50%;
  height: 40px;
  margin: 0 auto;
  color: #606166;
  text-align: center;
  overflow: hidden;
  background: #FFF;
  border: 1px dotted #909199;
}
.doning_prcoress{
  display: flex;
  align-items: center;
  justify-content: center;
}
.doning_prcoress .process_card{
    font-family: SimHei;
    font-size: 28px;
    font-weight: bolder;
    margin-right: 10px;
    color: #357DFF;
    font-style: normal;
}
.doning_prcoress .create_box {
  position: relative;
  width: 154px;
  height: 31px;
  color: #606166;
  text-align: center;
  overflow: hidden;
  background-image: url('../../../static/img/processbg.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
/* .create_box::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  z-index: 10;
  background: #fff;
  border-radius: 6px;
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  border: 1px dotted #909199; 

}
.create_box::after {
  content: '';
  position: absolute;
  left: -50%;
  top: 25%;
  width: 200%;
  height: 50%;
  background: conic-gradient(#357DFF, #357DFF 50%, transparent 50%, transparent);
  animation: rotate 2s linear infinite;
} */
@keyframes rotate {
  100% {
    transform: rotate(1turn);
  }
}
/* .process_card {
  position: absolute;
  top: 25%;
  left: 40%;
  z-index: 12;
} */

 
</style>
